package ink.metoo.gude.module.security.repository

import ink.metoo.gude.module.security.domain.ddl.User
import org.springframework.data.jpa.repository.Query
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation
import org.springframework.stereotype.Repository

@Repository
interface UserRepository : JpaRepositoryImplementation<User, Long> {

    @Query(
        """
        from User 
        where lower(email) = lower(:account) 
        or account = :account
        """
    )
    fun findByEmailOrAccount(account: String): User?

    fun findByEmail(email: String): User?

    fun existsByEmail(email: String): Boolean

    fun existsByAccount(account: String): Boolean

    @Query(
        """
        from User 
        where account like concat('%', :nickname, '%')
        order by createDate desc
        limit :size
        """
    )
    fun findAllByAccountLike(nickname: String, size: Int): List<User>

}